package ${package}.controller;

import ${package}.entity.${entityClassName};
import ${package}.vo.${voClassName};
import ${package}.service.${serviceClassName};

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
<#if config.controllerJavaConfig.isRestApi == true>
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
<#else>
import org.springframework.web.bind.annotation.${config.controllerJavaConfig.methodRequestMapping};
</#if>
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestParam;
<#if config.controllerJavaConfig.isUserSwagger == true>
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
</#if>

/**
<#if config.commentConfig.isAddFunctionComment == true>
 * 	${table.tableName}（${table.tableComment}）的controller层实现
</#if>
<#if config.commentConfig.isAddAuthorComment == true>
 *	@author ${author}
</#if>
<#if config.commentConfig.isAddDateComment == true>
 *	@Date ${date}
 </#if>
 */
<#if config.controllerJavaConfig.isUserSwagger == true>
@Api(tags = "${table.tableComment}",description = "${table.tableName}（${table.tableComment}）controller层接口")
</#if>
@Controller
@RequestMapping("${table.tableNameHump?lower_case}")
public class ${controllerClassName} {

    @Autowired
	private ${serviceClassName} ${serviceClassName?uncap_first};
    
    
<#if config.daoJavaConfig.isCreateCountMethod == true>
    /**
     <#if config.commentConfig.isAddFunctionComment == true>
     * 	根据查询条件，判断记录是否存在
     </#if>
     <#if config.commentConfig.isAddParamComment == true>
 	 *	@param query 查询条件{@link ${voClassName}}
 	 </#if>
 	 <#if config.commentConfig.isAddReturnComment == true>
 	 *	@return true -- 存在记录<br>
 	 *			false - 不存在
 	 </#if>
 	 <#if config.commentConfig.isAddAuthorComment == true>
	 *	@author ${author}
	</#if>
	<#if config.commentConfig.isAddDateComment == true>
	 *	@Date ${date}
	 </#if>
     */
    <#if config.controllerJavaConfig.isUserSwagger == true>
    @ApiOperation(value = "根据查询条件，判断记录是否存在",notes = "根据查询条件，判断记录是否存在")
    </#if>
    @ResponseBody
    <#if config.controllerJavaConfig.isRestApi == true>
    @GetMapping("/exist")
    <#else>
    @${config.controllerJavaConfig.methodRequestMapping}("/exist")
    </#if>
	public Object isExistQuery(${voClassName} query){
		<#if config.controllerJavaConfig.isCatchException == true>
		try {
            Boolean result = ${serviceClassName?uncap_first}.isExistQuery(query);
            return result;
        } catch (Exception e) {
        	e.printStackTrace();
            return null;
        }
        <#else>
        return ${serviceClassName?uncap_first}.isExistQuery(query);
        </#if>
	}
</#if>



<#if config.daoJavaConfig.isCreateGetOneByIdMethod == true>
	/**
	 <#if config.commentConfig.isAddFunctionComment == true>
     * 	根据主键判断是否存在
     </#if>
     <#if config.commentConfig.isAddParamComment == true>
 	 *	@param id 记录主键
 	 </#if>
 	 <#if config.commentConfig.isAddReturnComment == true>
 	 *	@return true -- 存在记录<br>
 	 *			false - 不存在
 	 </#if>
     <#if config.commentConfig.isAddAuthorComment == true>
     *	@author ${author}
     </#if>
      <#if config.commentConfig.isAddDateComment == true>
 	 *	@Date ${date}
 	 </#if>
     */
    <#if config.controllerJavaConfig.isUserSwagger == true>
    @ApiOperation(value = "根据主键判断是否存在",notes = "根据主键判断是否存在")
    @ApiImplicitParams({
    	<#if config.controllerJavaConfig.isRestApi == true>
    	@ApiImplicitParam(name = "id", value = "记录主键",paramType = "path",required = true)
    	<#else>
    	@ApiImplicitParam(name = "id", value = "记录主键",paramType = "query",required = true)
    	</#if>
    })
    </#if>
	@ResponseBody
    <#if config.controllerJavaConfig.isRestApi == true>
    @GetMapping("/exist/{id}")
    public Object isExistById(@PathVariable(value = "id")${table.primaryKey.javaType} id){
    <#else>
    @${config.controllerJavaConfig.methodRequestMapping}("/existById")
    public Object isExistById(${table.primaryKey.javaType} id){
    </#if>
    	<#if config.controllerJavaConfig.isCatchException == true>
		try {
            Boolean result = ${serviceClassName?uncap_first}.isExistById(id);
            return result;
        } catch (Exception e) {
        	e.printStackTrace();
            return null;
        }
        <#else>
        return ${serviceClassName?uncap_first}.isExistById(id);
        </#if>
	}
</#if>
	
	
<#if config.daoJavaConfig.isCreateCountMethod == true>
	/**
	 <#if config.commentConfig.isAddFunctionComment == true>
     * 	条件查询，获取数量
     </#if>
     <#if config.commentConfig.isAddParamComment == true>
 	 *	@param query 查询条件{@link ${voClassName}}
 	 </#if>
 	 <#if config.commentConfig.isAddReturnComment == true>
 	 *	@return int 符合条件的记录数量
 	 </#if>
     <#if config.commentConfig.isAddAuthorComment == true>
     *	@author ${author}
     </#if>
      <#if config.commentConfig.isAddDateComment == true>
 	 *	@Date ${date}
 	 </#if>
     */
    <#if config.controllerJavaConfig.isUserSwagger == true>
    @ApiOperation(value = "条件查询，获取数量",notes = "条件查询，获取数量")
    </#if>
	@ResponseBody
    <#if config.controllerJavaConfig.isRestApi == true>
    @GetMapping("/count")
    <#else>
    @${config.controllerJavaConfig.methodRequestMapping}("/count")
    </#if>
	public Object ${config.daoJavaConfig.countMethodName}(${voClassName} query){
		<#if config.controllerJavaConfig.isCatchException == true>
		try {
            Integer result = ${serviceClassName?uncap_first}.${config.daoJavaConfig.countMethodName}(query);
            return result;
        } catch (Exception e) {
        	e.printStackTrace();
            return null;
        }
        <#else>
        return ${serviceClassName?uncap_first}.${config.daoJavaConfig.countMethodName}(query);
        </#if>
	}
</#if>
	

	
<#if config.daoJavaConfig.isCreateGetAllMethod == true>
	/**
	 <#if config.commentConfig.isAddFunctionComment == true>
     * 	条件查询，获取全部
     </#if>
     <#if config.commentConfig.isAddParamComment == true>
 	 *	@param query 查询条件{@link ${voClassName}}
 	 </#if>
 	 <#if config.commentConfig.isAddReturnComment == true>
  	 *	@return List<${entityClassName}> 符合条件的记录
  	 </#if>
     <#if config.commentConfig.isAddAuthorComment == true>
     *	@author ${author}
     </#if>
      <#if config.commentConfig.isAddDateComment == true>
 	 *	@Date ${date}
 	 </#if>
     */
    <#if config.controllerJavaConfig.isUserSwagger == true>
    @ApiOperation(value = "条件查询，获取全部",notes = "条件查询，获取全部")
    </#if>
	@ResponseBody
    <#if config.controllerJavaConfig.isRestApi == true>
    @GetMapping("/list")
    <#else>
    @${config.controllerJavaConfig.methodRequestMapping}("/list")
    </#if>
	public Object ${config.daoJavaConfig.getAllMethodName}(${voClassName} query){
		<#if config.controllerJavaConfig.isCatchException == true>
		try {
            List<${entityClassName}> result = ${serviceClassName?uncap_first}.${config.daoJavaConfig.getAllMethodName}(query);
            return result;
        } catch (Exception e) {
        	e.printStackTrace();
            return null;
        }
        <#else>
        return ${serviceClassName?uncap_first}.${config.daoJavaConfig.getAllMethodName}(query);
        </#if>
	}
</#if>



<#if config.daoJavaConfig.isCreateGetAllPageMethod == true>
	/**
	 <#if config.commentConfig.isAddFunctionComment == true>
     * 	条件查询，分页获取
     </#if>
     <#if config.commentConfig.isAddParamComment == true>
 	 *	@param query 查询条件{@link ${voClassName}}
 	 *	@param pageNum 页数 ，默认1
 	 *	@param pageSize 页面大小 ，默认10
 	 </#if>
 	 <#if config.commentConfig.isAddReturnComment == true>
 	 *	@return List<${entityClassName}> 符合条件的记录，分页
 	 </#if>
     <#if config.commentConfig.isAddAuthorComment == true>
     *	@author ${author}
     </#if>
      <#if config.commentConfig.isAddDateComment == true>
 	 *	@Date ${date}
 	 </#if>
     */
     <#if config.controllerJavaConfig.isUserSwagger == true>
    @ApiOperation(value = "条件查询，分页获取",notes = "条件查询，分页获取")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "pageNum", value = "页数 ，默认1",paramType = "query",defaultValue = "1",required = false),
    	@ApiImplicitParam(name = "pageSize", value = "页面大小 ，默认10",paramType = "query",defaultValue = "10",required = false)
    })
    </#if>
	@ResponseBody
    <#if config.controllerJavaConfig.isRestApi == true>
    @GetMapping("/list/page")
    <#else>
    @${config.controllerJavaConfig.methodRequestMapping}("/list/page")
    </#if>
	public Object ${config.daoJavaConfig.getAllPageMethodName}(${voClassName} query,@RequestParam(defaultValue = "1")Integer pageNum,@RequestParam(defaultValue = "10")Integer pageSize){
		<#if config.controllerJavaConfig.isCatchException == true>
		try {
            List<${entityClassName}> result = ${serviceClassName?uncap_first}.${config.daoJavaConfig.getAllPageMethodName}(query,pageNum,pageSize);
            return result;
        } catch (Exception e) {
        	e.printStackTrace();
            return null;
        }
        <#else>
        return ${serviceClassName?uncap_first}.${config.daoJavaConfig.getAllPageMethodName}(query,pageNum,pageSize);
        </#if>
	}
</#if>



<#if config.daoJavaConfig.isCreateGetOneByIdMethod == true>
	/**
	 <#if config.commentConfig.isAddFunctionComment == true>
     * 	根据主键id获取
     </#if>
     <#if config.commentConfig.isAddParamComment == true>
 	 *	@param id 主键id
 	 </#if>
 	 <#if config.commentConfig.isAddReturnComment == true>
 	 *	@return ${entityClassName} 符合条件的记录
 	 </#if>
     <#if config.commentConfig.isAddAuthorComment == true>
     *	@author ${author}
     </#if>
      <#if config.commentConfig.isAddDateComment == true>
 	 *	@Date ${date}
 	 </#if>
     */
    <#if config.controllerJavaConfig.isUserSwagger == true>
    @ApiOperation(value = "根据主键id获取",notes = "根据主键id获取")
    @ApiImplicitParams({
    	<#if config.controllerJavaConfig.isRestApi == true>
    	@ApiImplicitParam(name = "id", value = "主键id",paramType = "path",required = true)
    	<#else>
    	@ApiImplicitParam(name = "id", value = "主键id",paramType = "query",required = true)
    	</#if>
    })
    </#if>
	@ResponseBody
    <#if config.controllerJavaConfig.isRestApi == true>
    @GetMapping("/{id}")
    public Object ${config.daoJavaConfig.getOneByIdMethodName}(@PathVariable(value = "id")${table.primaryKey.javaType} id){
    <#else>
    @${config.controllerJavaConfig.methodRequestMapping}("/${config.daoJavaConfig.getOneByIdMethodName}")
    public Object ${config.daoJavaConfig.getOneByIdMethodName}(${table.primaryKey.javaType} id){
    </#if>
    	<#if config.controllerJavaConfig.isCatchException == true>
		try {
            ${entityClassName} result = ${serviceClassName?uncap_first}.${config.daoJavaConfig.getOneByIdMethodName}(id);
            return result;
        } catch (Exception e) {
        	e.printStackTrace();
            return null;
        }
        <#else>
        return ${serviceClassName?uncap_first}.${config.daoJavaConfig.getOneByIdMethodName}(id);
        </#if>
	}
</#if>



	
<#if config.daoJavaConfig.isCreateDeleteByIdMethod == true>
	/**
	 <#if config.commentConfig.isAddFunctionComment == true>
     * 	根据主键id删除记录
     </#if>
     <#if config.commentConfig.isAddParamComment == true>
 	 *	@param id 主键id
 	 </#if>
 	 <#if config.commentConfig.isAddReturnComment == true>
 	 *	@return int 删除的数量
 	 </#if>
     <#if config.commentConfig.isAddAuthorComment == true>
     *	@author ${author}
     </#if>
      <#if config.commentConfig.isAddDateComment == true>
 	 *	@Date ${date}
 	 </#if>
     */
    <#if config.controllerJavaConfig.isUserSwagger == true>
    @ApiOperation(value = "根据主键id删除记录",notes = "根据主键id删除记录")
    @ApiImplicitParams({
    	<#if config.controllerJavaConfig.isRestApi == true>
    	@ApiImplicitParam(name = "id", value = "主键id",paramType = "path",required = true)
    	<#else>
    	@ApiImplicitParam(name = "id", value = "主键id",paramType = "query",required = true)
    	</#if>
    })
    </#if>
	@ResponseBody
    <#if config.controllerJavaConfig.isRestApi == true>
    @DeleteMapping("/{id}")
    public Object ${config.daoJavaConfig.deleteByIdMethodName}(@PathVariable(value = "id")${table.primaryKey.javaType} id){
    <#else>
    @${config.controllerJavaConfig.methodRequestMapping}("/${config.daoJavaConfig.deleteByIdMethodName}")
    public Object ${config.daoJavaConfig.deleteByIdMethodName}(${table.primaryKey.javaType} id){
    </#if>
    	<#if config.controllerJavaConfig.isCatchException == true>
		try {
            Integer result = ${serviceClassName?uncap_first}.${config.daoJavaConfig.deleteByIdMethodName}(id);
            return result;
        } catch (Exception e) {
        	e.printStackTrace();
            return null;
        }
        <#else>
        return ${serviceClassName?uncap_first}.${config.daoJavaConfig.deleteByIdMethodName}(id);
        </#if>
	}
</#if>



<#if config.daoJavaConfig.isCreateInsertNotNullFieldMethod == true>
	/**
	 <#if config.commentConfig.isAddFunctionComment == true>
     * 	非空字段新增
     </#if>
     <#if config.commentConfig.isAddParamComment == true>
 	 *	@param entity 实体JavaBean，详情看{@link ${entityClassName}}
 	 </#if>
 	 <#if config.commentConfig.isAddReturnComment == true>
 	 *	@return int 插入的数量
 	 </#if>
     <#if config.commentConfig.isAddAuthorComment == true>
     *	@author ${author}
     </#if>
      <#if config.commentConfig.isAddDateComment == true>
 	 *	@Date ${date}
 	 </#if>
     */
    <#if config.controllerJavaConfig.isUserSwagger == true>
    @ApiOperation(value = "非空字段新增",notes = "非空字段新增")
    </#if>
	@ResponseBody
    <#if config.controllerJavaConfig.isRestApi == true>
    @PostMapping("")
    <#else>
    @${config.controllerJavaConfig.methodRequestMapping}("/insert")
    </#if>
	public Object ${config.daoJavaConfig.insertNotNullFieldMethodName}(${entityClassName} entity){
		<#if config.controllerJavaConfig.isCatchException == true>
		try {
            Integer result = ${serviceClassName?uncap_first}.${config.daoJavaConfig.insertNotNullFieldMethodName}(entity);
            return result;
        } catch (Exception e) {
        	e.printStackTrace();
            return null;
        }
        <#else>
        return ${serviceClassName?uncap_first}.${config.daoJavaConfig.insertNotNullFieldMethodName}(entity);
        </#if>
	}
</#if>



<#if config.daoJavaConfig.isCreateUpdateNotNullFieldMethod == true>
	/**
	 <#if config.commentConfig.isAddFunctionComment == true>
     * 	根据主键，非空字段更新，主键不更新
     </#if>
     <#if config.commentConfig.isAddParamComment == true>
 	 *	@param entity 实体JavaBean，详情看{@link ${entityClassName}}
 	 </#if>
 	 <#if config.commentConfig.isAddReturnComment == true>
 	 *	@return int 更新的数量
 	 </#if>
     <#if config.commentConfig.isAddAuthorComment == true>
     *	@author ${author}
     </#if>
      <#if config.commentConfig.isAddDateComment == true>
 	 *	@Date ${date}
 	 </#if>
     */
    <#if config.controllerJavaConfig.isUserSwagger == true>
    @ApiOperation(value = "根据主键，非空字段更新，主键不更新",notes = "根据主键，非空字段更新，主键不更新")
    </#if>
	@ResponseBody
    <#if config.controllerJavaConfig.isRestApi == true>
    @PutMapping("")
    <#else>
    @${config.controllerJavaConfig.methodRequestMapping}("/update")
    </#if>
	public Object ${config.daoJavaConfig.updateNotNullFieldMethodName}(${entityClassName} entity){
		<#if config.controllerJavaConfig.isCatchException == true>
		try {
            Integer result = ${serviceClassName?uncap_first}.${config.daoJavaConfig.updateNotNullFieldMethodName}(entity);
            return result;
        } catch (Exception e) {
        	e.printStackTrace();
            return null;
        }
        <#else>
        return ${serviceClassName?uncap_first}.${config.daoJavaConfig.updateNotNullFieldMethodName}(entity);
        </#if>
	}
</#if>
	
}
